add_executable(mesen2
    main.cpp
    mainwindow.cpp
    qpicturebox.cpp
    qrender.cpp
    qkeymanager.cpp
    qmousemanager.cpp
    qsettingsdialog.cpp
    minisoundmanager.cpp
    miniaudio.c
    qfilesearchdialog.cpp

    ${CORE_SRC}
    ${UTIL_SRC}
    ${SEVENZIP_SRC}
    ${LUA_SRC}
)

if (WIN32)
    target_link_libraries(mesen2 PRIVATE winmm xinput)
    set_target_properties(mesen2 PROPERTIES WIN32_EXECUTABLE ON)
    target_sources(mesen2 PRIVATE
        ${CMAKE_SOURCE_DIR}/Windows/XInputManager.cpp
    )
elseif(UNIX)
    target_sources(mesen2 PRIVATE
        ${CMAKE_SOURCE_DIR}/Linux/LinuxGameController.cpp
        ${CMAKE_SOURCE_DIR}/Linux/libevdev/libevdev.c
    )
endif()

target_link_libraries(mesen2
    PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Sql
)

if (QT_VERSION_MAJOR EQUAL 6)
    target_link_libraries(mesen2 PRIVATE Qt${QT_VERSION_MAJOR}::OpenGLWidgets)
endif()

set_target_properties(mesen2 PROPERTIES
    OUTPUT_NAME mesen2
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

file(COPY ${CMAKE_SOURCE_DIR}/Firmware DESTINATION ${CMAKE_BINARY_DIR}/bin)

# install mesen2 to /opt/mesen2/
install(TARGETS mesen2 DESTINATION /opt/mesen2)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/Firmware DESTINATION /opt/mesen2)

# Create desktop file from template
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mesen2.desktop.in ${CMAKE_BINARY_DIR}/mesen2.desktop @ONLY)

# Install desktop file
install(FILES ${CMAKE_BINARY_DIR}/mesen2.desktop
        DESTINATION /usr/share/applications)

# Install icon
install(FILES ${CMAKE_SOURCE_DIR}/Linux/appimage/Mesen.48x48.png
        DESTINATION /usr/share/pixmaps
        RENAME mesen2.png)

